package com.qfoud.edu.framwork.interceptor.impl;

import com.qfoud.edu.framwork.annotation.Interceptor;
import com.qfoud.edu.framwork.container.InterceptorContainer;
import com.qfoud.edu.framwork.interceptor.base.AbstractInterceptor;
import com.qfoud.edu.framwork.interceptor.base.InterceptorChain;

import javax.servlet.http.HttpServletRequest;
import java.util.Iterator;
import java.util.Map;

/**
 * @author xiaobobo
 * @title: InterceptorChainImpl
 * @projectName cd-java-2303-project-parent
 * @description: 这个就是用来专门调用拦截器的实现的这个类
 * @date 2023/5/10  14:11
 */
public class InterceptorChainImpl implements InterceptorChain {

    private static final InterceptorChainImpl interceptorChain=new InterceptorChainImpl();

    private InterceptorChainImpl(){}
    public static InterceptorChainImpl getInstance(){
        return interceptorChain;
    }

    @Override
    public void dealReq(HttpServletRequest req) {
        //获取拦截器这个容器
        Map<Integer, AbstractInterceptor> interceptorMap = InterceptorContainer.getInterceptorMap();
        Iterator<AbstractInterceptor> it = interceptorMap.values().iterator();
        while (it.hasNext()){
            AbstractInterceptor abstractInterceptor = it.next();
            abstractInterceptor.dealReq(req);
        }
    }
}
